unit Configure;

{$mode objfpc}{$H+}

//========================================================================================
//
// Unit : Configure.pas
//
// Description : This module provides
//
// Called By : Final : Finalize
//             Init : Initialize
//             Main : frmConfigure.ShowModal
//
// Calls :
//
// Ver. : 1.00
//
// Date : 22 Mar 2016
//
//========================================================================================

interface

uses
  Classes, Buttons, Controls, Dialogs, FileUtil, Forms, Graphics, INIFiles,
  sqlite3conn, StdCtrls, SysUtils;

type

  { TfrmConfigure }
  TfrmConfigure = class(TForm)
    bbtOK: TBitBtn;
    bbtCancel: TBitBtn;
    edtDataPath: TEdit;
    edtAppPath: TEdit;
    edtReportsPath: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    sbtBrowseReportsPath: TSpeedButton;
    sbtBrowseDataPath: TSpeedButton;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    fstrAppPath: string;
    fstrDataPath: string;
    fstrReportsPath: string;
    fblnConfigurationFile : boolean;
    procedure SetAppPath(const cstrAppPath: string);
    procedure SetDataPath(const cstrDataPath: string);
    procedure SetReportsPath(const cstrReportsPath: string);
  public
    { Public Declarations }
    const
  const
    cstrDefaultDatabaseName = 'DefaultApplicationData.db';
    cstrApplicationDatabaseName = 'ApplicationData.db';
    cstrDefReportsDirName = 'Reports';
    cstrDefDataDirName = 'Data';
    procedure ReadConfigurationFile;
    procedure WriteConfigurationFile;
  published
    { Property declarations }
    property strAppPath: string
      read fstrAppPath write SetAppPath;
    property strDataPath: string
      read fstrDataPath write SetDataPath;
    property strReportsPath: string
      read fstrReportsPath write SetReportsPath;
    property blnNewConfigurationFile : boolean
      read fblnConfigurationFile write fblnConfigurationFile;
  end;// TfrmConfigure = class(TForm)


var
  frmConfigure: TfrmConfigure;

implementation

{$R *.lfm}

const
  cstrConfigurationFileName = 'WestcoastWoodturning.cfg';

  cstrSectionApplication = 'APPLICATION';
  cstrKeyConfigurationFile = 'ConfigurationFile';
  cstrKeyDataPath = 'Data Path';
  cstrKeyReportsPath = 'Reports Path';

var
  ConfigurationFile: TINIFile;
  vstrConfigurationFileName: string;

//========================================================================================
//
//========================================================================================
//          PRIVATE ROUTINES
//========================================================================================

//========================================================================================
//          PUBLIC ROUTINES
//========================================================================================

//========================================================================================
//          PROPERTY ROUTINES
//========================================================================================
procedure TfrmConfigure.SetAppPath(const cstrAppPath: string);
begin
  fstrAppPath := cstrAppPath;
  edtAppPath.Text := fstrAppPath;
end;// procedure TfrmConfigure.SetAppPath

//----------------------------------------------------------------------------------------
procedure TfrmConfigure.SetDataPath(const cstrDataPath: string);
begin
  fstrDataPath := cstrDataPath;
  edtDataPath.Text := fstrDataPath;
end;// procedure TfrmConfigure.SetDataPath

//----------------------------------------------------------------------------------------
procedure TfrmConfigure.SetReportsPath(const cstrReportsPath: string);
begin
  fstrReportsPath := cstrReportsPath;
  edtReportsPath.Text := fstrReportsPath;
end;// procedure TfrmConfigure.SetReportsPath

//========================================================================================
//          MENU ROUTINES
//========================================================================================

//========== MAIN MENU ==========

//========================================================================================
//          COMMAND BUTTON ROUTINES
//========================================================================================

//========================================================================================
//          CONTROL ROUTINES
//========================================================================================

//========================================================================================
//          FILE ROUTINES
//========================================================================================
procedure TfrmConfigure.ReadConfigurationFile;
begin

  vstrConfigurationFileName := strAppPath + '\' + cstrConfigurationFileName;

  ConfigurationFile := TINIFile.Create(vstrConfigurationFileName);
  blnNewConfigurationFile := ConfigurationFile.ReadBool(cstrSectionApplication,
                                                   cstrKeyConfigurationFile,
                                                   True);
  strReportsPath := ConfigurationFile.ReadString(cstrSectionApplication,
                                                  cstrKeyReportsPath,
                                                  fstrReportsPath);
  strDataPath := ConfigurationFile.ReadString(cstrSectionApplication, cstrKeyDataPath,
                                                                 fstrDataPath);

end;// procedure TfrmConfigure.ReadConfigurationFile

//========================================================================================
procedure TfrmConfigure.WriteConfigurationFile;
begin

  ConfigurationFile.WriteBool(cstrSectionApplication, cstrKeyConfigurationFile,
                                                      fblnConfigurationFile);
  ConfigurationFile.WriteString(cstrSectionApplication, cstrKeyReportsPath,
                                                        strReportsPath);
  ConfigurationFile.WriteString(cstrSectionApplication, cstrKeyDataPath, strDataPath);

  ConfigurationFile.UpdateFile;
  ConfigurationFile.Free;

end;// procedure TfrmConfigure.WriteConfigurationFile

//========================================================================================
//          FORM ROUTINES
//========================================================================================
procedure TfrmConfigure.FormCreate(Sender: TObject);
begin

end;// procedure TfrmConfigure.FormCreate

//----------------------------------------------------------------------------------------
procedure TfrmConfigure.FormShow(Sender: TObject);
begin

end;// procedure TfrmConfigure.FormShow

//========================================================================================
end.// unit Configure

